package com.xtpt.disaster.utils;

import com.xtpt.disaster.bean.JobDetail;
import com.xtpt.disaster.bean.ParametersDBBackup;
import com.xtpt.disaster.bean.TaskInfo;
import com.xtpt.disaster.common.consts.ScheduleTypeEnum;
import com.xtpt.disaster.common.consts.StatusConst;
import com.xtpt.disaster.common.consts.TaskTypeEnum;

import java.util.Date;

public class JobDetailUtil {

    public static JobDetail generateBackUpJobDetail(ParametersDBBackup taskInfo, Integer sourceDbType, Long dbId)
    {
        Long jobId = IDGenerator.longid();
        Date startTime = TimeUtil.dateMaker();
        JobDetail jobDetail = new JobDetail();
        jobDetail.setJobType(taskInfo.getTaskType());
        jobDetail.setJobName(taskInfo.getTaskName());
        jobDetail.setTaskId(taskInfo.getTaskId());
        jobDetail.setJobId(jobId);
        jobDetail.setJobStartTime(startTime);
        jobDetail.setSourceDbType(sourceDbType);
        jobDetail.setScheduleType(taskInfo.getTaskExectype());
        jobDetail.setJobStatus(StatusConst.RUNNING);
        jobDetail.setDbId(dbId);
        jobDetail.setJobDesc(taskInfo.getTaskDesc());
        return jobDetail;
    }

    public static JobDetail generateRestoreJobDetail(Long taskID,String taskName, Integer sourceDbType, Long dbId,String taskDesc)
    {
        Long jobId = IDGenerator.longid();
        Date startTime = TimeUtil.dateMaker();
        JobDetail jobDetail = new JobDetail();
        jobDetail.setJobType(TaskTypeEnum.RECOVER.getValue());
        jobDetail.setJobName(taskName);
        jobDetail.setTaskId(taskID);
        jobDetail.setJobId(jobId);
        jobDetail.setJobStartTime(startTime);
        jobDetail.setSourceDbType(sourceDbType);
        jobDetail.setScheduleType(ScheduleTypeEnum.IMMEDIATELY.getValue());
        jobDetail.setJobStatus(StatusConst.RUNNING);
        jobDetail.setDbId(dbId);
        jobDetail.setJobDesc(taskDesc);
        return jobDetail;
    }
}
